package com.hwadee.springboot.controller.ExamController;

import com.hwadee.springboot.entity.Mistake;
import com.hwadee.springboot.entity.R;
import com.hwadee.springboot.entity.SaveWrongQuestionsRequest;
import com.hwadee.springboot.entity.WrongQuestionDto;
import com.hwadee.springboot.service.MistakeService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mistake")
public class MistakeController {

    @Resource
    private MistakeService mistakeService;

    @PostMapping("/saveWrongQuestions")
    public R<Boolean> saveWrongQuestions(@RequestBody SaveWrongQuestionsRequest request) {
        return mistakeService.saveWrongQuestions(request);
    }

    @GetMapping("/student/{studentId}/mistakes")
    public R<List<Mistake>> getStudentMistakes(@PathVariable Long studentId) {
        return R.ok(mistakeService.getStudentMistakes(studentId));
    }

    /**
     * 删除错题
     *
     * @param mistakeId 错题ID
     * @return 删除结果
     */
    @DeleteMapping("/delete/{mistakeId}")
    public R<Boolean> deleteMistake(@PathVariable Long mistakeId, @RequestParam Long studentId) {
        boolean result = mistakeService.deleteMistakeByStudentAndId(studentId, mistakeId);
        return result ? R.ok(true) : R.error(500, "删除失败");
    }
}